import request from "@/utils/requset";
// 获取个人资料
const getUserProfile = () => {
  return request({
    url: "/v1_0/user/profile",
    method: "get",
  });
};

// 获取用户基本信息
const userBaseInfo = () => {
  return request({
    url: "/v1_0/user",
    method: "get",
  });
};

// 编辑用户照片资料（头像、身份证照片）
const upLoadImage = (fd) => {
  return request({
    url: "/v1_0/user/photo",
    method: "PATCH",
    data: fd,
  });
};

//编辑用户个人资料
const editUserInfo = (obj) => {
  let newobj = {
    name: "",
    gender: "",
    birthday: "",
    real_name: "",
    intro: "",
  };
  for (let prop in newobj) {
    // console.log(prop);
    // console.log(obj[prop]);
    if (obj[prop] === undefined) {
      delete newobj[prop];
    } else {
      newobj[prop] = obj[prop];
    }
  }
  return request({
    url: "/v1_0/user/profile",
    method: "PATCH",
    data: newobj,
  });
};

// 刷新token
const refreshtoken = () => {
  return request({
    url: "/v1_0/authorizations",
    method: "PUT",
    headers: {
      Authorization: "Bearer " + localStorage.getItem("refresh_token"),
    },
  });
};
export {
  getUserProfile,
  userBaseInfo,
  upLoadImage,
  editUserInfo,
  refreshtoken,
};
